package com.udi.project.business.local.di.thread;


import com.udi.common.utils.spring.SpringUtils;
import com.udi.project.business.local.di.service.DiMangeService;
import com.udi.project.business.utils.httpApi.OkHttp1;
import com.udi.project.business.utils.redis.RedisUtils;

import java.io.IOException;
import java.util.Map;

/**
 * @author Admin
 * DI申报子线程
 */
public class Submit extends Thread{
    private RedisUtils redisUtils;
    private OkHttp1 okHttp1;
    private DiMangeService diMangeService;


    public Submit(){
        this.redisUtils = SpringUtils.getBean(RedisUtils.class);
        this.okHttp1 = SpringUtils.getBean(OkHttp1.class);
        this.diMangeService = SpringUtils.getBean(DiMangeService.class);
    }


    @Override
    public void run() {
        //JSONObject jsonObject = new JSONObject();
        //设置线程名称
        this.setName("Submit");
        Map key = redisUtils.hmget("deviceRecordKey");
        for(Object ke:key.keySet()){
                try {
                    String ims = okHttp1.PostProductLogo((String) ke, (String)key.get(ke));
                   if(!ims.equals("200")){
                       redisUtils.lSet("ThreadHint","{\"messg\":\""+ims+"\",\"TypeNumber\":5002},");
                   }
                }catch (IOException e){
                    e.printStackTrace();
            }
        }
        /** 将redis对象取出 反序列化 向数据库注入DI去向（用于DI一维码，未使用，生成GS1）信息数据
        List<Product> sf = (List<Product>) redisUtils.get("list");
        for(Product key:sf){
            key.setDeviceRecordKey("serial");
            key.setZXXSDYCPBS("logo");
            diMangeService.insertInformation(sf);
        }*/
        redisUtils.del("serial","logo","list");
        redisUtils.del("deviceRecordKey","ZXXSDYCPBS");
    }
}
